clear
set more off
cd "D:\data_replication"


use estimation\1_data_format\production_imports.dta, clear
keep if year < 2006
sort pc8plus year quarter declarant
by pc8plus year quarter declarant: egen imports_total_pc8plus = sum(imports_value_pc8plus) 
by pc8plus year quarter declarant: keep if _n == 1
keep pc8plus year quarter declarant imports_total_pc8plus


sort year quarter declarant
by year quarter declarant: egen imports_total = sum(imports_total_pc8plus)
gen share_pc8plus = imports_total_pc8plus / imports_total

keep pc8plus year quarter declarant share_pc8plus
order declarant year quarter pc8plus share_pc8plus
sort declarant year quarter pc8plus share_pc8plus
 
save estimation\4_demand_estimation\4_cobb_douglas_weights\share_pc8plus.dta, replace
export delimited using estimation\4_demand_estimation\4_cobb_douglas_weights\share_pc8plus.csv, replace


clear
import delimited estimation\4_demand_estimation\4_cobb_douglas_weights\data_save.csv

merge 1:1 pc8plus declarant quarter year using estimation\4_demand_estimation\4_cobb_douglas_weights\share_pc8plus.dta
keep if _merge == 3
drop _merge

export delimited using estimation\4_demand_estimation\4_cobb_douglas_weights\data_save_shares.csv, replace
